package com.quickask.interceptor;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.Interceptor;
import org.apache.struts2.ServletActionContext;

import java.util.Map;

/**
 * Created by hackway on
 * Date: 2015/12/22.
 * Time:15:23
 */
public class SessionInterceptor implements Interceptor {
    @Override
    public void destroy() {

    }

    @Override
    public void init() {

    }

    @Override
    public String intercept(ActionInvocation actionInvocation) throws Exception {

        ActionContext act = actionInvocation.getInvocationContext();
        String userId = ServletActionContext.getRequest().getParameter("userId");
        String token = ServletActionContext.getRequest().getParameter("token");
        String uid = "";
        Map sessionMap = act.getSession();
        try {
            uid = (String) sessionMap.get(userId);
        } catch (NullPointerException e) {
            act.put("message", "Session过期，请重新登录！");
            return "3";
        }
        if (sessionMap.get(userId)!=null && sessionMap.get(userId).equals(token)) {

        }
        return null;
    }
}
